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

how to load dataframe in mtsim? #8

Closed
yglpyn8888 opened this issue Dec 7, 2021 · 6 comments
Closed

how to load dataframe in mtsim? #8

yglpyn8888 opened this issue Dec 7, 2021 · 6 comments

Comments

@yglpyn8888
Copy link

Just like the parameter 'df' of Env in anytrading, how can I load my own dataframe in MtSim . I see in the example that only the .pkl file is loaded

@AminHP
Copy link
Owner

AminHP commented Dec 7, 2021

As I explained here, you can override the download_data method and load your own dataframes. It's a bit more complicated than anytrading. For each symbol, you should load a dataframe and specify its SymbolInfo. The symbol info is required for precise calculations. Currently, it is filled by retrieving the information from MetaTrader but you can create an instance of this class and fill it manually.

@yglpyn8888
Copy link
Author

@AminHP
Hi Amin, I probably know what to do next, but it's a little different from what I expected. I thought I should rewrite the load_symbols method to load my own df. So what's the difference between the download_data() and load_symbols()?

According to their source code, the load_symbols method is loaded from a filename:str(actually a path), which seems to be more in line with my requirements?

def download_data(
        self, symbols: List[str], time_range: Tuple[datetime, datetime], timeframe: Timeframe
    ) -> None:
    from_dt, to_dt = time_range
    for symbol in symbols:
        si, df = retrieve_data(symbol, from_dt, to_dt, timeframe)
        self.symbols_info[symbol] = si
        self.symbols_data[symbol] = df

def load_symbols(self, filename: str) -> bool:
    if not os.path.exists(filename):
        return False
    with open(filename, 'rb') as file:
        self.symbols_info, self.symbols_data = pickle.load(file)
    return True

@AminHP
Copy link
Owner

AminHP commented Dec 7, 2021

The load_symbols method can only load a file which was previously saved by the save_symbols method. And the save_symbols should be called after filling the simulator.symbols_info and simulator.symbols_data attributes. These attributes are filled in the download_data. So, in order to make load_symbols work correctly, the proper data should be provided first in the download_data method.

@yglpyn8888
Copy link
Author

oh, that's clear, thanks!

@TanapongAUS
Copy link

May I ask, How can I fix trading volume or lot size?

thanks in advance for your answer

@SUSHANTH009
Copy link

oh, that's clear, thanks!

please can you share your notebook to upload custom data file

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

No branches or pull requests

4 participants