Register and share your invite link to earn from video plays and referrals.

Search results for matplotlib
matplotlib community
One keyword maps to one global community path.
Create community
People
Not Found
Tweets including matplotlib
How i trade with the Black-Scholes Model: i built Black-Scholes from SCRATCH six months into my quant journey the formula everyone learns in school, the one that won Merton and Scholes a Nobel, i figured if it was famous enough to have a Nobel, it was famous enough to trust that was my first MISTAKE here's what i actually learned from building it, using it, and losing money with it --------------- the build: Black-Scholes takes 5 inputs and outputs an option price, that's stock price, strike price, time to expiry, risk-free rate and volatility tech stack i used: > Python 3.11 as the base language > scipy(dot)stats for the normal cumulative distribution function > numpy for the vectorized math when i extended it across multiple strikes > yfinance to pull SPY option chain data for backtesting > matplotlib for the initial visualization the entire pricing engine was around 40 lines of Python, i wrote it in a jupyter notebook first, then moved it into a proper module once i started using it for real trades when i first ran it and compared to real SPY option prices, the model was within 2-3% on liquid at-the-money options with 30-90 days to expiry i thought i had cracked the CODE --------------- what actually worked: pricing accuracy on at-the-money SPY options was solid enough that i could use the model as a reference, not as gospel, but as a check against what the market was showing me the GREEKS were the real win tho i extended the code to output all 4 first-order Greeks from the same closed-form formula: > delta = how much the option moves for a $1 stock move > gamma = how fast delta itself changes as the stock moves > theta = the daily cost of holding the position from time decay > vega = sensitivity to a 1% change in implied volatility i built a simple streamlit dashboard on top of the pricing engine that showed all 4 Greeks on my open positions in real time, refreshed every 30 seconds against live yfinance data for the first time i actually understood WHY my positions were moving the way they were --------------- what broke, expensively: my first real trade was SPY puts before a Fed meeting i used 14% historical vol as my sigma, model priced the puts at $2.85, live market at $3.40 implied vol had already jumped to 22% ahead of the print market dropped 2% like i expected, my model P&L said i should be up 60%, i closed up 28% IV CRASHED from 22% to 13% the moment the Fed resolved, my puts lost the vega premium even though the direction was right lesson: Black-Scholes assumes constant vol, real markets don't work like that the other assumptions broke too: > log-normal returns fail on tail events, this is why the vol smile exists > no-dividends assumption cost me on ex-dividend dates, my code didn't adjust for it > frictionless markets are a joke, my real fills were 5-10% worse than mid-price --------------- how i actually trade with it now: i stopped using Black-Scholes to price options, i use it to read the market the gap between my model price and the market price is implied vol vs my assumption, that's INFORMATION, not a mispricing to fade example: model says $2.85 using 14% vol, market says $3.40, market is implying 22% on that strike then i decide with vega: > if 22% looks too high going into an event, i short vega through a spread > if 22% still looks cheap, i buy vega > i never trade the gap as a pure mispricing the Greeks are what i actually check before every trade: > delta: my directional exposure across the book > gamma: how fast delta changes on big moves, i size smaller when gamma is high > theta: daily cost or income from time decay > vega: my volatility exposure, i cut this before earnings and Fed meetings --------------- the honest breakdown: Black-Scholes is not a trading model, it's a FRAMEWORK for understanding options the formula prices options for a market that doesn't exist, no jumps, no vol changes, no dividends, no slippage but the intuition it gives you about Greeks is priceless build it once from SCRATCH in Python, price a few real options against the market, then watch it break on your first real trade that's how you actually learn options for serious pricing you eventually move to Heston, but that's a rabbit hole for another post use Black-Scholes for the Greeks, read the price gap as implied vol, trade with vega instead of against the model
Show more
LLM Knowledge Bases Something I'm finding very useful recently: using LLMs to build personal knowledge bases for various topics of research interest. In this way, a large fraction of my recent token throughput is going less into manipulating code, and more into manipulating knowledge (stored as markdown and images). The latest LLMs are quite good at it. So: Data ingest: I index source documents (articles, papers, repos, datasets, images, etc.) into a raw/ directory, then I use an LLM to incrementally "compile" a wiki, which is just a collection of .md files in a directory structure. The wiki includes summaries of all the data in raw/, backlinks, and then it categorizes data into concepts, writes articles for them, and links them all. To convert web articles into .md files I like to use the Obsidian Web Clipper extension, and then I also use a hotkey to download all the related images to local so that my LLM can easily reference them. IDE: I use Obsidian as the IDE "frontend" where I can view the raw data, the the compiled wiki, and the derived visualizations. Important to note that the LLM writes and maintains all of the data of the wiki, I rarely touch it directly. I've played with a few Obsidian plugins to render and view data in other ways (e.g. Marp for slides). Q&A: Where things get interesting is that once your wiki is big enough (e.g. mine on some recent research is ~100 articles and ~400K words), you can ask your LLM agent all kinds of complex questions against the wiki, and it will go off, research the answers, etc. I thought I had to reach for fancy RAG, but the LLM has been pretty good about auto-maintaining index files and brief summaries of all the documents and it reads all the important related data fairly easily at this ~small scale. Output: Instead of getting answers in text/terminal, I like to have it render markdown files for me, or slide shows (Marp format), or matplotlib images, all of which I then view again in Obsidian. You can imagine many other visual output formats depending on the query. Often, I end up "filing" the outputs back into the wiki to enhance it for further queries. So my own explorations and queries always "add up" in the knowledge base. Linting: I've run some LLM "health checks" over the wiki to e.g. find inconsistent data, impute missing data (with web searchers), find interesting connections for new article candidates, etc., to incrementally clean up the wiki and enhance its overall data integrity. The LLMs are quite good at suggesting further questions to ask and look into. Extra tools: I find myself developing additional tools to process the data, e.g. I vibe coded a small and naive search engine over the wiki, which I both use directly (in a web ui), but more often I want to hand it off to an LLM via CLI as a tool for larger queries. Further explorations: As the repo grows, the natural desire is to also think about synthetic data generation + finetuning to have your LLM "know" the data in its weights instead of just context windows. TLDR: raw data from a given number of sources is collected, then compiled by an LLM into a .md wiki, then operated on by various CLIs by the LLM to do Q&A and to incrementally enhance the wiki, and all of it viewable in Obsidian. You rarely ever write or edit the wiki manually, it's the domain of the LLM. I think there is room here for an incredible new product instead of a hacky collection of scripts.
Show more
0
2.9K
60.9K
7.4K
Forward to community