forked from sftwre/CryptoFund
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
49 lines (33 loc) · 1.06 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os, sys
import pandas as pd
import matplotlib
# Qt backend for Mac
if sys.platform == "darwin":
matplotlib.use('Qt5Agg')
import mplfinance as mpf
class CoinGraph:
def __init__(self, coin:str):
self.coin = coin.lower() # coin name
self.root = "./data"
self.df = None # data frame of prices
"""
load coin data into dataframe
"""
def loadCoinData(self) -> pd.DataFrame:
# initial csv read
if type(self.df) != pd.DataFrame:
csvFile = os.path.join(self.root, self.coin + "_price.csv")
with open(csvFile) as csv:
self.df = pd.read_csv(csv, index_col=0, parse_dates=True)
return self.df
"""
"""
def render(self):
if type(self.df) != pd.DataFrame:
print(f"Error: Must load data for {self.coin} before usage")
return
mpf.plot(self.df, type="candle", style="charles",
title=self.coin.title(), ylabel_lower="Volume")
cg = CoinGraph("Bitcoin")
df_bitcoin = cg.loadCoinData()
cg.render()