-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/implement ai option valuation analysis page (#16)
* implement option valuation page * implement option valuation page * implement option page * remove local test code
- Loading branch information
Showing
9 changed files
with
545 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CompanyAnalysisGPTResponseExample } from './companyAnalysisdef' | ||
import { OptionValuationAnalysisGPTResponseExample } from './optionValuationAnalysisdef' | ||
|
||
export const GPTModelSelectDef = ['gpt-4o', 'gpt-4o-mini', 'o1-preview', 'o1-mini', 'gpt-4-turbo', 'gpt-3.5-turbo'] | ||
export const AnalysisSelectDef = [ | ||
{ | ||
name: 'CompanyAnalysis', | ||
display_name: 'Company Analysis', | ||
description: `Using GPT models to analyze company data and provide insights on valuation, performance, growth, dividends, balance sheet, analyst sentiment, and more.`, | ||
defaultOutput: CompanyAnalysisGPTResponseExample | ||
}, | ||
{ | ||
name: 'OptionValuationAnalysis', | ||
display_name: 'Option Valuation Analysis', | ||
description: `Leverages GPT models to analyze option contracts, offering detailed insights into valuation, risk factors, market dynamics, and potential hazards.`, | ||
defaultOutput: OptionValuationAnalysisGPTResponseExample | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
export const OptionValuationAnalysisAPI = "/stock-minehunter/api/task/do-ai-option-valuation-analysis" | ||
|
||
export const OptionValuationAnalysisDef = [ | ||
{ | ||
name: 'BSM_EWMAHisVol', | ||
display_name: 'Black Scholes Merton EWMA Historical Volatility', | ||
default: true, | ||
}, | ||
{ | ||
name: 'MC_EWMAHisVol', | ||
display_name: 'Monte Carlo EWMA Historical Volatility', | ||
default: true, | ||
}, | ||
{ | ||
name: 'BT_EWMAHisVol', | ||
display_name: 'Binomial Tree EWMA Historical Volatility', | ||
default: true, | ||
}, | ||
{ | ||
name: 'KellyCriterion', | ||
display_name: 'Kelly Criterion', | ||
default: true, | ||
}, | ||
{ | ||
name: 'exerciseProbability', | ||
display_name: 'Probability of Exercise of Option', | ||
default: true, | ||
}, | ||
{ | ||
name: 'delta', | ||
display_name: 'Delta', | ||
default: true, | ||
}, | ||
{ | ||
name: 'gamma', | ||
display_name: 'Gamma', | ||
default: true, | ||
}, | ||
{ | ||
name: 'vega', | ||
display_name: 'Vega', | ||
default: true, | ||
}, | ||
{ | ||
name: 'theta', | ||
display_name: 'Theta', | ||
default: true, | ||
}, | ||
{ | ||
name: 'rho', | ||
display_name: 'Rho', | ||
default: true, | ||
}, | ||
] | ||
|
||
export const OptionValuationAnalysisGPTResponseExample = `# Analysis of DIS Put Option Contract | ||
## Introduction | ||
This report provides a comprehensive analysis of a put option contract for The Walt Disney Company (DIS). The focus is on assessing the risks and valuation for both the buyer and the seller of the option, utilizing the provided data. The analysis covers the option's key parameters, market context, valuation metrics, and the potential risks involved. | ||
## Option Contract Details | ||
- **Underlying Asset**: The Walt Disney Company (DIS) | ||
- **Current Date**: October 13, 2024 | ||
- **Option Type**: Put | ||
- **Strike Price**: $90.00 | ||
- **Expiration Date**: October 18, 2024 | ||
- **Time to Expiration**: 5 days | ||
- **Current Stock Price**: $94.13 | ||
- **Last Trade Date**: October 11, 2024 | ||
- **Last Price**: $0.14 | ||
- **Bid**: $0.14 | ||
- **Ask**: $0.16 | ||
- **Change**: -$0.24 | ||
- **Percent Change**: -63.16% | ||
- **Volume**: 3,277 contracts | ||
- **Open Interest**: 15,575 contracts | ||
- **Implied Volatility**: 27.64% | ||
- **Historical Volatility (EWMA)**: 18.26% | ||
- **Earnings Date**: November 14, 2024 | ||
## Market Context | ||
- **Stock Performance**: The current stock price of DIS is $94.13, trading above the put option's strike price of $90.00. | ||
- **Time to Expiry**: With only 5 days remaining until expiration, time decay is a significant factor affecting the option's value. | ||
- **Earnings Announcement**: The earnings date is set for November 14, 2024, which is after the option's expiration. Therefore, earnings-related volatility is unlikely to impact this option. | ||
- **Market Volatility**: The implied volatility of the option is higher than the historical volatility, suggesting that the market anticipates increased future volatility in the stock price. | ||
## Valuation Analysis | ||
### Implied vs. Historical Volatility | ||
- **Implied Volatility (IV)**: 27.64% | ||
- **Historical Volatility (EWMA)**: 18.26% | ||
- **Analysis**: The higher IV relative to historical volatility implies that the option is priced with an expectation of higher future volatility. This can make the option more expensive for buyers and potentially beneficial for sellers. | ||
### Option Pricing Models | ||
- **Binomial Tree Model (EWMA Historical Volatility)**: | ||
- **Theoretical Price**: $0.0377 | ||
- **Observation**: The theoretical price is lower than the market price, indicating that the option might be overpriced based on historical volatility. | ||
- **Black-Scholes-Merton (BSM) Model**: | ||
- **Price with EWMA Historical Volatility**: -$1.00 (Note: A negative price indicates a calculation error or model limitation, possibly due to very low time to expiry and volatility input.) | ||
### Option Greeks | ||
- **Delta**: -0.0385 | ||
- **Interpretation**: For every $1 decrease in the stock price, the option's price increases by approximately $0.0385. The small delta reflects the option's out-of-the-money status. | ||
- **Gamma**: 0.0345 | ||
- **Interpretation**: Indicates the rate of change of delta; a measure of convexity. A higher gamma suggests greater sensitivity of delta to price movements. | ||
- **Theta**: -0.0504 | ||
- **Interpretation**: The option loses about $0.0504 in value each day due to time decay, significant given the short time to expiration. | ||
- **Vega**: 0.0111 | ||
- **Interpretation**: For each 1% change in implied volatility, the option's price changes by approximately $0.0111. | ||
- **Rho**: -0.00073 | ||
- **Interpretation**: Insensitive to interest rate changes due to the short time to expiration. | ||
### Probability Metrics | ||
- **Exercise Probability**: 4.152% | ||
- **Interpretation**: There's a low probability that the option will be in-the-money at expiration, aligning with the out-of-the-money status. | ||
### Kelly Criterion | ||
- **Kelly Criterion for Buying**: -5.0461 | ||
- **Interpretation**: A negative value suggests a less favorable position for buyers. | ||
- **Kelly Criterion for Selling**: 0.9651 | ||
- **Interpretation**: A positive value close to 1 indicates a potentially favorable opportunity for sellers to maximize capital growth over time. | ||
## Risk Analysis | ||
### For the Buyer | ||
- **Limited Risk**: The maximum loss is the premium paid ($0.14 per share). | ||
- **Low Probability of Profit**: With a 4.152% chance of exercise, the likelihood of the option being profitable is low. | ||
- **Time Decay (Theta Risk)**: The negative theta indicates the option's value erodes quickly with time, especially significant in the last week before expiration. | ||
- **Volatility Risk**: A decrease in implied volatility can reduce the option's price, adversely affecting the buyer. | ||
- **Liquidity Risk**: The option has decent volume and open interest, reducing liquidity concerns. | ||
### For the Seller | ||
- **Limited Profit**: Maximum gain is the premium received ($0.14 per share). | ||
- **Assignment Risk**: Low exercise probability reduces the risk of assignment, but unexpected market movements could lead to assignment. | ||
- **Large Potential Loss**: If the stock price falls significantly below the strike price, the seller faces substantial losses. | ||
- **Volatility Risk**: An increase in implied volatility can lead to a higher buy-back price if the seller wants to close the position before expiration. | ||
- **Margin Requirements**: Sellers may need to meet margin requirements, tying up capital. | ||
## Conclusion | ||
- **Buyer Perspective**: | ||
- The put option offers a low-cost opportunity to profit from a potential decline in DIS stock price. However, the low exercise probability and significant time decay diminish the attractiveness of this position. | ||
- Negative Kelly Criterion value suggests that the expected return does not justify the risk for buyers. | ||
- **Seller Perspective**: | ||
- Sellers can benefit from the high implied volatility and time decay, collecting the premium with a low probability of the option being exercised. | ||
- Positive Kelly Criterion value indicates a favorable expected return, making selling the option more attractive. | ||
- **Market Outlook**: | ||
- The higher implied volatility suggests market participants expect increased volatility in the near term, yet with only 5 days to expiration, significant stock movements are less likely. | ||
- The absence of major events before expiration (e.g., earnings report) reduces the likelihood of drastic stock price changes. | ||
--- | ||
**Recommendations**: Market participants should carefully weigh the limited profit potential against the risks. Sellers may find this option favorable due to the positive Kelly Criterion and the benefits of time decay. Buyers should be cautious given the low probability of exercise and the rapid erosion of premium value as expiration approaches. | ||
**Disclaimer**: This analysis is for informational purposes only and does not constitute financial advice. Investment decisions should be based on individual financial situations and risk tolerance.` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React, { useState } from 'react' | ||
import TextField from '@mui/material/TextField' | ||
import InputLabel from '@mui/material/InputLabel' | ||
import FormControl from '@mui/material/FormControl' | ||
import Select from '@mui/material/Select' | ||
import OutlinedInput from '@mui/material/OutlinedInput' | ||
import ListItemText from '@mui/material/ListItemText' | ||
import MenuItem from '@mui/material/MenuItem' | ||
import Checkbox from '@mui/material/Checkbox' | ||
import Stack from '@mui/material/Stack' | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs' | ||
import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker' | ||
import shortid from 'shortid' | ||
import dayjs from 'dayjs' | ||
|
||
import { GPTModelSelectDef } from '../../common/gpt/commonDef' | ||
|
||
import gptInvestingAssistantStyle from './gptInvestingAssistant.module.scss' | ||
|
||
|
||
const ITEM_HEIGHT = 48 | ||
const ITEM_PADDING_TOP = 8 | ||
export const MenuProps = { | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 13.5 + ITEM_PADDING_TOP, | ||
width: 250, | ||
}, | ||
}, | ||
} | ||
|
||
export const DatePickerComponent = ({ datePickerRef, label, defaultDate }) => { | ||
const [value, setValue] = useState(dayjs(defaultDate)) | ||
datePickerRef.current.getValue = () => { | ||
return dayjs(value).format('YYYY-MM-DD') | ||
} | ||
const handleChange = (newValue) => { | ||
setValue(newValue) | ||
} | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DesktopDatePicker | ||
label={label} | ||
inputFormat="MM/DD/YYYY" | ||
value={value} | ||
onChange={handleChange} | ||
renderInput={(params) => <TextField size="small" {...params} />} | ||
/> | ||
</LocalizationProvider> | ||
); | ||
} | ||
|
||
export const ModelComponent = ({ modelInputRef }) => { | ||
const [modelArg, setModelArg] = useState(0); | ||
const [modelInputValue, setModelInputValue] = useState(GPTModelSelectDef[0]); | ||
|
||
const handleModelChange = (event) => { | ||
const selectedModel = GPTModelSelectDef[event.target.value]; | ||
setModelArg(event.target.value); | ||
setModelInputValue(selectedModel); | ||
} | ||
|
||
const renderModelInput = (value) => { | ||
return ( | ||
<form noValidate autoComplete="off" style={{ paddingLeft: "5px", width: "inherit" }}> | ||
<TextField | ||
className={gptInvestingAssistantStyle.valueText} | ||
placeholder="Select or type the model name" | ||
label={"GPT Model"} | ||
variant="outlined" | ||
value={value} | ||
onChange={(e) => setModelInputValue(e.target.value)} | ||
size="small" | ||
inputRef={modelInputRef} | ||
/> | ||
</form> | ||
) | ||
} | ||
|
||
return ( | ||
<div style={{ display: "inline-flex", width: "100%" }}> | ||
<FormControl size="small" variant="outlined" style={{ minWidth: "150px" }}> | ||
<InputLabel htmlFor="modelArg-select">{'Model Name'}</InputLabel> | ||
<Select | ||
native | ||
value={modelArg} | ||
displayEmpty | ||
onChange={handleModelChange} | ||
label={'Model Name'} | ||
> | ||
{GPTModelSelectDef.map((value, index) => ( | ||
<option key={shortid.generate()} index={index} value={index}> | ||
{value} | ||
</option> | ||
))} | ||
</Select> | ||
</FormControl> | ||
{renderModelInput(modelInputValue)} | ||
</div> | ||
) | ||
} | ||
|
||
export const FiltersComponent = ({ filtersRef, filterName, filtersDef}) => { | ||
const [filtersArg, setFiltersArg] = useState(filtersRef.current) | ||
return ( | ||
<FormControl size="small" variant="outlined" style={{width:"100%"}}> | ||
<InputLabel htmlFor="filtersArg-select">{filterName}</InputLabel> | ||
<Select | ||
value={filtersArg} | ||
multiple | ||
onChange={(event) => { | ||
filtersRef.current = event.target.value | ||
setFiltersArg(event.target.value) | ||
}} | ||
label={filterName} | ||
input={<OutlinedInput label={filterName} />} | ||
renderValue={(selected) => selected.map((value) => filtersDef[value].display_name).join(', ')} | ||
MenuProps={MenuProps} | ||
> | ||
{ | ||
filtersDef.map((value, index) => { | ||
return ( | ||
<MenuItem key={index} value={index}> | ||
<Checkbox checked={filtersArg.includes(index)} /> | ||
<ListItemText primary={value.display_name} /> | ||
</MenuItem>) | ||
}) | ||
} | ||
</Select> | ||
</FormControl>) | ||
} |
Oops, something went wrong.