Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinkfish package
#11
(May-16-2020, 06:33 PM)snippsat Wrote:
Quote:Yes there is,so this a Notebook i run as test.
As you see no errors.

this part I have no errors either, error starts the next section.
#i start to have error after i ran this section. 
tlog.cash = capital

import time
t0 = time.time()

"""
# This is the slowest (2.42 s)
for i in range(len(ts.index)):

    date = ts.index[i]
    high = ts['high'][i]
    low = ts['low'][i]
    close = ts['close'][i]
    sma50 = ts['sma50'][i]
    sma200 = ts['sma200'][i]

# This is still slow (2.53 s)
for i, (index, row) in enumerate(ts.iterrows()):

    date = index
    high = row['high']
    low = row['low']
    close = row['close']
    sma50 = row['sma50']
    sma200 = row['sma200']


# using .at[] is fast (832 ms)
for i, index in enumerate(ts.index):

    date = index
    high = ts.at[index, 'high']
    low = ts.at[index, 'low']
    close = ts.at[index, 'close']
    sma50 = ts.at[index, 'sma50']
    sma200 = ts.at[index, 'sma200']

# using itertuples is fastest for looping (378 ms)
for i, row in enumerate(ts.itertuples()):

    date = row.Index.to_pydatetime()
    high = row.high
    low = row.low
    close = row.close
    sma50 = row.sma50
    sma200 = row.sma200
"""

for i, row in enumerate(ts.itertuples()):

    date = row.Index.to_pydatetime()
    high = row.high; low = row.low; close = row.close
    sma50 = row.sma50; sma200 = row.sma200
    end_flag = True if (i == len(ts) - 1) else False
    shares = 0
    
    # close all positions on last trade day
    if end_flag:
        shares = tlog.exit_trade(date, close)
    # buy
    elif (tlog.num_open_trades() == 0
          and row.sma50 > row.sma200 and ts['sma50'][i-1] <= ts['sma200'][i-1]):

        # enter buy in trade log
        shares = tlog.enter_trade(date, close)  
    # sell
    elif (tlog.num_open_trades() > 0
          and sma50 < sma200 and ts['sma50'][i-1] >= ts['sma200'][i-1]):

        # enter sell in trade log
        shares = tlog.exit_trade(date, close)

    if shares > 0:
        print("{0} BUY  {1} {2} @ {3:.2f}".format(
              date, shares, symbol, close))
    elif shares < 0:
        print("{0} SELL {1} {2} @ {3:.2f}".format(
              date, -shares, symbol, close))

    # record daily balance
    dbal.append(date, high, low, close, tlog.shares, tlog.cash)  

t1 = time.time()
total = t1-t0
print(total)
        
Quote:Some step this will create a virtual environment with conda .
I use cmder but commands are just the same in cmd.
You may need to install git
# Make
G:\Anaconda3\Scripts
λ conda create --name pink_env

# Activate
G:\Anaconda3\Scripts
λ activate pink_env

# Cd to pink
(pink_env) G:\Anaconda3\Scripts
λ cd ..

(pink_env) G:\Anaconda3
λ cd envs\pink_env\

(pink_env) G:\Anaconda3
λ cd envs\pink_env\

# Clone Repo
(pink_env) G:\Anaconda3\envs\pink_env
λ git clone https://github.com/fja05680/pinkfish.git

# Remove these 3 from requirements.txt save as req.txt
importlib-metadata==0.18
empyrical==0.5.3
TA-Lib==0.4.17

# Install req.txt
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ conda install --file req.txt

# new file req1.txt
importlib-metadata==0.18
empyrical==0.5.3

# Install req1.txt with pip
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ pip install -r req1.txt

# Install NoteBook
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ conda install -c conda-forge jupyterlab
From gohlke download TA_Lib‑0.4.18‑cp37‑cp37m‑win_amd64.whl
# Install
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ pip install TA_Lib-0.4.18-cp37-cp37m-win_amd64.whl
Processing g:\anaconda3\envs\pink_env\pinkfish\ta_lib-0.4.18-cp37-cp37m-win_amd64.whl
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.18
Finish Pray
# Start Jupyterlab
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ jupyter lab
does the code above I ran in CMD or I put in as python code in main.ipynb ?
I want to double-check first. So I don't run into the same mistake leads to uninstall the anaconda and re-install it.
Thank you very much for your time.
Reply


Messages In This Thread
Pinkfish package - by buunaanaa - May-15-2020, 05:22 AM
RE: Pinkfish package - by snippsat - May-15-2020, 06:20 AM
RE: Pinkfish package - by buunaanaa - May-15-2020, 05:48 PM
RE: Pinkfish package - by snippsat - May-15-2020, 06:31 PM
RE: Pinkfish package - by buunaanaa - May-15-2020, 07:22 PM
RE: Pinkfish package - by snippsat - May-15-2020, 10:04 PM
RE: Pinkfish package - by buunaanaa - May-16-2020, 04:48 PM
RE: Pinkfish package - by buunaanaa - May-18-2020, 05:49 AM
RE: Pinkfish package - by buunaanaa - May-16-2020, 07:55 PM
RE: Pinkfish package - by snippsat - May-16-2020, 06:33 PM
RE: Pinkfish package - by buunaanaa - May-17-2020, 04:24 PM
RE: Pinkfish package - by buunaanaa - May-18-2020, 05:43 PM
RE: Pinkfish package - by buunaanaa - May-18-2020, 07:11 PM
RE: Pinkfish package - by snippsat - May-16-2020, 09:48 PM
RE: Pinkfish package - by snippsat - May-17-2020, 04:47 PM
RE: Pinkfish package - by snippsat - May-18-2020, 10:44 AM
RE: Pinkfish package - by snippsat - May-18-2020, 08:10 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020