Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new tutorial for multi-currencies arbitrage using Bellman-Ford Algorithm #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

leo-ai-for-trading
Copy link

@leo-ai-for-trading leo-ai-for-trading commented May 27, 2023

Description

Adding docs for the calculation of local volatility model

Related Issue

N/A

Motivation and Context

tutorial for new members (in particular with heavy Math background)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • New feature (non-breaking change which adds functionality)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • My branch follows the naming convention bug-<issue#>- or feature-<issue#>-

@leo-ai-for-trading leo-ai-for-trading changed the title Adjust docs for the new implied volatility methodology #885 Adjust docs for the new implied volatility methodology May 27, 2023
@leo-ai-for-trading leo-ai-for-trading changed the title Adjust docs for the new implied volatility methodology Add new tutorial for multi-currencies arbitrage using Bellman-Ford Algorithm May 27, 2023
## Description
Replying to this issue

Related Issue
How to extract Implied volatility from Quantconnect QuantConnect#47


Types of changes
-[ ] Bug fix (non-breaking change which fixes an issue)
-[ ] Refactor (non-breaking change which improves implementation)
-[ ] New feature (non-breaking change which adds functionality)
-[ x] Non-functional change (xml comments/documentation/etc)
Checklist:
-[ x] My code follows the code style of this project.
-[ x] I have read the CONTRIBUTING [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
-[ x] My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>
## Description
Adding nee tutorial

Types of changes
-[ ] Bug fix (non-breaking change which fixes an issue)
-[ ] Refactor (non-breaking change which improves implementation)
-[ ] New feature (non-breaking change which adds functionality)
-[ x] Non-functional change (xml comments/documentation/etc)
Checklist:
-[ x] My code follows the code style of this project.
-[ x] I have read the CONTRIBUTING [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
-[ x] My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>
Capital Structure Arbitrage
## Description
Adding nee tutorial

Types of changes
-[ ] Bug fix (non-breaking change which fixes an issue)
-[ ] Refactor (non-breaking change which improves implementation)
-[ ] New feature (non-breaking change which adds functionality)
-[ x] Non-functional change (xml comments/documentation/etc)
Checklist:
-[ x] My code follows the code style of this project.
-[ x] I have read the CONTRIBUTING [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
-[ x] My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>
@LouisSzeto LouisSzeto self-requested a review April 10, 2024 06:13
@LouisSzeto
Copy link

Thank you for the commits! Looks great and technical. Leaving a few comments above.
BTW I think Local_Stochastic_Volatility_Model.ipynb is in a wrong location. Please put it into the folder like the others.

@LouisSzeto
Copy link

For capital_structure_arbitrage.ipynb, it is a piece of information with math formula development right? So maybe you can change it into a .md file with latex to type in the formula.

@leo-ai-for-trading
Copy link
Author

leo-ai-for-trading commented Apr 10, 2024 via email

@leo-ai-for-trading
Copy link
Author

leo-ai-for-trading commented Apr 10, 2024 via email

@leo-ai-for-trading
Copy link
Author

leo-ai-for-trading commented Apr 10, 2024 via email

@LouisSzeto
Copy link

@leo-ai-for-trading Local_Stochastic_Volatility_Model.ipynb This notebook should be placed in the same folder as the others.

" price2 = qb.History(ticker2, start_time, end_time, Resolution.Tick)['lastprice']\n",
" price3 = qb.History(ticker3, start_time, end_time, Resolution.Tick)['lastprice']\n",
"\n",
" df = pd.DataFrame({'symbol':list(),'price':list()})\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May add a comment on why using negative log price (for minimum distance and eliminate compounding effect...)

" @start_time: date to start getting data\n",
" @end_time: last day of getting data\n",
" \"\"\"\n",
"\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is some restrictions on how do you choose the crypto. Say if we choose BTCUSD, ETHUSD & BTCETH, there will be 4 currencies and 3 directional edges that always get positive results. If we're doing arbitrage, we should do BTCUSD, USDETH & ETHBTC to force a long-short balance in each currency. It will be good to add description above.

Comment on lines +129 to +131
" price1 = qb.History(ticker1, start_time, end_time, Resolution.Tick)['lastprice']\n",
" price2 = qb.History(ticker2, start_time, end_time, Resolution.Tick)['lastprice']\n",
" price3 = qb.History(ticker3, start_time, end_time, Resolution.Tick)['lastprice']\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tick resolution might not align with time, recommend to use second instead. Also, there might not be trading information some illiquid currencies, it maybe better to use History[QuoteBar].

Comment on lines +117 to +123
"\\begin{aligned}\n",
"&\\begin{aligned}\n",
"\\sigma_{l o c}^2(K, T, S) & =\\sigma^2-\\lambda \\frac{K \\frac{\\partial C}{\\partial K}}{\\frac{1}{2} K^2 \\frac{\\partial^2 C}{\\partial K^2}} \\\\\n",
"& =\\sigma^2+2 \\lambda \\sigma \\sqrt{T} \\frac{N\\left(d_2\\right)}{N^{\\prime}\\left(d_2\\right)}\n",
"\\end{aligned}\\\\\n",
"&d_2=\\frac{\\log S / K+\\lambda T}{\\sigma \\sqrt{T}}-\\frac{\\sigma \\sqrt{T}}{2}\n",
"\\end{aligned}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display issue

"source": [
"\n",
" \n",
"def get_data(sym1:str,sym2:str, sym3:str , start_time: datetime, end_time: datetime):\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - we use (self, arg1: type1 = a, arg2: type2 = b, arg3: type3 = c) -> type4:. Please fix the nit

" def __getitem__(self,v):\n",
" return self.neighbors[v]\n",
" \n",
" def add_node(self,name):\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

" self.weight.append({})\n",
" return self.name2node[name]\n",
" \n",
" def add_edge(self,name_u,name_v,weight_uv=None):\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

" self.add_arc(name_u, name_v, weight_uv) \n",
" self.add_arc(name_v, name_u, weight_uv)\n",
"\n",
" def add_arc(self,name_u,name_v,weight_uv=None):\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Comment on lines +250 to +251
"r = 0.0341 \n",
"D = 0.0\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use Lean's InterestRateProvider

InterestRateProvider().GetInterestRate(goog_df.index[...])    # sub in the time

and DividendYieldProvider

DividendYieldProvider(goog).GetDividendYield(goog_df.index[...])    # sub in the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants