Skip to content
Advertisement

Y finance Date alignment

This might be a relatively difficult question;

The scope of the code I want to write, is to automate the alignment of Dates that i pull from yfinance regarding BTC and S&P 500

since the S&P500 (SPY) is not traded on weekends, but BTC is, I want to automatically delete the columns of dates from BTC that fall on weekends (or days where the S&P isn’t traded), to consistently align my 2 dataframes.

In this case I have 15 data rows in BTC, whereas I only have 10 in SPY

I only need data where the dates match

Does anyone have an idea how I could do that?

JavaScript

Advertisement

Answer

Given your understanding that what you want to achieve is to have the BTC-USD data frame on the same trading day as the SPY trading day, the easiest way to do this is to reassign the BTC data frame with the SPY index.

JavaScript

Full code:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement