I've written this code for my Bachelor thesis: "Semantica del valore, modelli fattoriali e teoria del portafoglio nel mercato delle criptovalute"
A simple script that allows you to download historical price data of all pairs against BUSD, USDT, BTC, BNB, ETH from Binance. This script allows you to get statistics from the price candles and to apply basic concepts of Modern Portfolio Theory by Harry Markowitz.
Candles, portfolio weights and returns are also saved in CSV format.
This program requires NodeJS to be installed: https://nodejs.org/it/download/
STEPS:
-
Open your terminal (Start > cmd)
-
git clone https://github.com/fedemagnani/Binance_Watcher.js.git
-
cd Binance_Watcher.js
-
npm install
(in order to install all the dependencies) -
node main
If you want to add other timeframes, just populate the array called timeframes
at the top of main.js
script.
If you want to change the quote assets, just edit the array called quoteList
at the top of main.js
script.
This will allow you to download the last 1000 candles of each timeframe you've set (by default: "5m","30m","1h","4h","1d","1w") of ANY PAIR against the quote assets you've set (by default: "BUSD","USDT","BTC","ETH","BNB"). For example, you can check the daily USDT candles by going to /Candele_USDT/1d/
and then select the pair you want.
For what regards asset allocation, the script will calculate weights for:
☼ Efficient Frontier
☼ Optimal Risky Portfolio
☼ Minimum Variance Portfolio
You just have to set the number of candles required for each pair in order to be considered in the calculation of the portfolios: you can do it by changing the requiredCandles
variable in main.js
By default, this script will compute the optimal portfolio built on any timeframe you've specified and on any pair related to the quote assets you've set. You can check the optimal portfolio weights, expected return, standard deviation and sharpe ratio by going to /Portafogli_Ottimi/timeframe/example.json
In order to see graphs like this you need to change directory by typing on the command line:
cd GRAFICI_statistica_descrittiva_unicaserie
Then, you need to edit the quote
and timeframe
variables in base.js
in order to have data from the desired quote asset and timeframe.
Finally, type on the command line
electron app
In addition, if you go to /Statistica_Descrittiva_UnicaSerie_1d/
you can check the file that summarizes some statistics computed on the daily candles of each USDT pair, The statistics included are:
• Expected Return
• Variance
• Standard Deviation
• Sharpe Ratio
• Value at risk (fifth percentile)
• Ninety-fifth percentile
• Skewness
• Kurtosis
• Downside Risk (change variable target
in main.js
)