Getting error when I created a code/strategy based on vwap - not sure how to correct the error #57693
Replies: 2 comments
-
The code you generated appears to set up a framework for stock trading, incorporating functionality for retrieving a list of stocks, calculating volume-weighted moving averages (VWMA) using TA-Lib, and simulating basic buy and sell operations on stock data. However, there are several issues: the function |
Beta Was this translation helpful? Give feedback.
-
Crypto assets can be utilized in various ways, depending on your needs and goals. They can serve as a medium for transactions, enabling fast, borderless payments with cryptocurrencies like Bitcoin, Ethereum, or stablecoins. They can also be leveraged for investments, with opportunities in holding, trading, or staking assets to earn passive income. Additionally, crypto assets are central to decentralized finance (DeFi) platforms, where you can lend, borrow, or earn yields. They’re also used in non-fungible tokens (NFTs) for digital ownership and in smart contracts to automate processes. Choosing the right method depends on your familiarity with blockchain technology and risk tolerance. For more info, visit fintechzoom |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
Here is the code I generated using gpt
import pandas as pd
import numpy as np
import ta-lib
def get_stocks():
"""Returns a list of stocks."""
stocks = ["PNB", "MOTHERSON", "BEL", "BHEL", "IOC", "GAIL", "L_TFH", "TATASTEEL", "IBULHSGFIN", "BEL", "RECLTD", "ASHOKLEYLAND", "INDUSTOWERS", "NTPC", "BANKBARODA", "PFC", "ZEEL"]
return stocks
def get_vwma(data, window):
"""Returns the volume-weighted moving average of the given data for the given window."""
return talib.VWAP(data["Open"], data["High"], data["Low"], data["Close"], window)
def buy_stock(data, stock, price):
"""Buys 1000 shares of the given stock at the given price."""
data.loc[data["Symbol"] == stock, "Quantity"] += 1000
data.loc[data["Symbol"] == stock, "Price"] = price
def sell_stock(data, stock, price):
"""Sells 1000 shares of the given stock at the given price."""
data.loc[data["Symbol"] == stock, "Quantity"] -= 1000
data.loc[data["Symbol"] == stock, "Price"] = price
def main():
"""Runs the main program."""
Get a list of stocks.
stocks = get_stocks()
Get the current price and volume for each stock.
data = pd.DataFrame()
for stock in stocks:
data = data.append({"Symbol": stock, "Price": np.nan, "Volume": np.nan}, ignore_index=True)
Get the 5-minute VWAP for each stock.
for i in range(len(data)):
data.loc[i, "VWAP"] = get_vwma(data, 5)[i]
Loop over the data and buy or sell stocks as needed.
for i in range(len(data) - 1):
# If the close price crosses the vwma from below, buy the stock.
if data.loc[i, "Close"] < data.loc[i, "VWAP"] and data.loc[i + 1, "Close"] >= data.loc[i + 1, "VWAP"]:
buy_stock(data, data.loc[i, "Symbol"], data.loc[i, "Close"])
Print the final results.
print(data)
if name == "main":
main()
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting ta-lib
Using cached TA-Lib-0.4.26.tar.gz (272 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from ta-lib) (1.22.4)
Building wheels for collected packages: ta-lib
error: subprocess-exited-with-error
× Building wheel for ta-lib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Building wheel for ta-lib (pyproject.toml) ... error
ERROR: Failed building wheel for ta-lib
Failed to build ta-lib
ERROR: Could not build wheels for ta-lib, which is required to install pyproject.toml-based projects
Above error is in google colab - how do I fix it?
Beta Was this translation helpful? Give feedback.
All reactions