alvarobartt / investiny

🤏🏻 `investpy` but made tiny
https://alvarobartt.github.io/investiny
MIT License
301 stars 36 forks source link

Date column #8

Closed rozhix closed 1 year ago

rozhix commented 1 year ago

HI there. I use historical_data function, I want to have Date column too, what should I do?

alvarobartt commented 1 year ago

Hi, @rozhix that's listed in the TODOs in the README.md so expect that to be done soon! 🤗 Thanks for your patience!

OGsiji commented 1 year ago

Hi @alvarobartt This method should fix the date issue

from investiny import historical_data
import pandas as pd
from datetime import timedelta
from datetime import datetime

def add_day(date, days):
    date = datetime.strptime(date, "%m/%d/%Y")  + timedelta(days)
    modified = datetime.strftime(date, "%m/%d/%Y")
    return modified

def get_results(investing_id, from_date,to_date):
    data = pd.DataFrame(historical_data(investing_id=investing_id, from_date=from_date, to_date=to_date))  
    dates = pd.DataFrame(pd.bdate_range(add_day(from_date, +1), add_day(to_date, days=-1)))
    assert len(data) == len(dates), 'The length of data is greater than the date length'
    #print(dates)
    final_data = pd.concat([dates,data],axis=1)

    return final_data
OGsiji commented 1 year ago

it needs more testing though

alvarobartt commented 1 year ago

Hi @OGsiji so I'm already adding that feature, so expect it to be released either later today or tomorrow (check my timeframe in my GitHub profile in case of doubt), thanks!