I'm struggling to find a python tool/library that could track performance of my portfolio based on some csv or list of transactions of buys and sells. It should be able to deal with situations where I buy 100 shares of some stock and sell only 14 shares later, so it should deal with impartial or incomplete transactions. It'd be great if I just could upload a csv with transaction dates and amounts and the library would figure out daily snapshots of performance analytics.
I see plenty of back-testing portfolio management tools that re-balance or project or optimize some ephemeral portfolio based on what would I buy and hold or buy and sell in the future. But it's not what I'm after. I have a list with transaction details and I want to see analytics, tracking, performance analysis on the back of it.
Thanks.
Related
I am new to Backtrader and I can't figure out how to write the following strategy:
Every morning it places a limit buy order at 80% of Open price. If the order is executed during the day (i.e. Low price < the limit price for that day), then sell the stock at Close.
I am using Yahoo's OHLC daily data.
Can any one show me how to write the Strategy part of the code? I posted a similar question on BT's official forum but couldn't get an answer.
Thanks.
I'm currently exploring different ways to judge and predict the performance of various offers and marketing campaigns. I have a list of metrics to pull from which I'm currently using now to predict performance, such as:
Day the offer was sent
Month
Weather
Time of Day
+more
And for my performance metric, I use
Redemption Rate (For every offer sent, how many times was it redeemed) - This is how I judge success
But one of the most important metrics is the offer itself, which I know in the form of a text-string.
Here are a few user-generated examples.
Get $4.00 off a large pizza
Receive 20% off your next order
Buy any Chocolate Milkshake, get another one half price
Two wraps for $7.50
Free cookie with any purchase
..and hundred's more
Now, I know there's very important information in those text stings, but I don't know the best way to analyze it and extract key information. For example, in this text it shows the product its advertising, the discount, the dollar amount, the percentage off, etc. I need a generalized way to go through each string (I'm assuming through some tolkenized method), and extract relevant information.
I'm hoping to get some input on how I could analyze these strings, eventually with the purpose of generating a string-based dataset (along with the other aforementioned data points) that I can use for predictions.
I am writing my code using python 3.0.
Any advice is greatly appreciated. Thanks.
I have the following job description text:
Why settle for an ordinary sales career, when you can put more life in your career with us? Colonial Life has an immediate opening for SALES REPRESENTATIVES to join our growing team.\\r\\rWe are a leader in worksite marketing. We work with employers and their employees to provide benefit solutions in one neat package: benefits communication, enrollment, and personal insurance products.\\r\\rSkills/backgrounds associated with success are:\\r\\r Experience attaining challenging sales goals.\\r Ability to identify and prioritize sales opportunities.\\r Effective verbal and written communication skills, and\xa0ability to successfully engage all levels of customer base.\\r Self-motivation and drive; willing to invest time in developing client relationships. \\r\\r\\rCareer Opportunities:\\r\\r\\r Prospect, market and deliver benefit communications and enrollment solutions to decision makers.\\r Present voluntary product solutions to employees. \\r\\r\\r\\rWe provide the tools, training and support to help you succeed. With Colonial Life, you can:\\r\xa0 \\r\\r Achieve more than just sales – enjoy being a benefits counselor.\\r Work with a sound company that’s had a solid history of integrity and growth for more than 70 years.\\r Enjoy strong earnings potential, even in your first year, plus competitive bonuses and incentives. Average first-year income for our top new benefit counselors hit $105,000 last year. \\r Grow and refine your skills through our proven phone prospecting system and structured sales training program.\\r Enjoy a flexible work schedule.\\r Earn what you’re worth, help people, and have fun doing it! \\r\\r'
I'm trying to:
a) get rid of all the "\r", "\r\r" or "\r\r\r" characters in the main text
b) print it in sentences so it's more readable
How do I do both a) and b)?
I have tried re.sub(r'[^ \w\.]', '', sentence) for a) and it removed the "\" but not the "r" so I ended up with something like that:
'Why settle for an ordinary sales career when you can put more life in your career with us Colonial Life has an immediate opening for SALES REPRESENTATIVES to join our growing team.rrWe are a leader in worksite marketing. We work with employers and their employees to provide benefit solutions in one neat package benefits communication enrollment and personal insurance products.rrSkillsbackgrounds associated with success arerr ...
I would like to develop a trend following strategy via back-testing a universe of stocks; lets just say all NYSE or S&P500 equities. I am asking this question today because I am unsure how to handle the storage/organization of the massive amounts of historical price data.
After multiple hours of research I am here, asking for your experience and awareness. I would be extremely grateful for any information/awareness you can share on this topic
Personal Experience background:
-I know how to code. Was a Electrical Engineering major, not a CS major.
-I know how to pull in stock data for individual tickers into excel.
Familiar with using filtering and custom studies on ThinkOrSwim.
Applied Context:
From 1995 to today lets evaluate the best performing equities on a relative strength/momentum basis. We will look to compare many technical characteristics to develop a strategy. The key to this is having data for a universe of stocks that we can run backtests on using python, C#, R, or any other coding language. We can then determine possible strategies by assesing the returns, the omega ratio, median excess returns, and Jensen's alpha (measured weekly) of entries and exits that are technical driven.
Here's where I am having trouble figuring out what the next step is:
-Loading data for all S&P500 companies into a single excel workbook is just not gonna work. Its too much data for excel to handle I feel like. Each ticker is going to have multiple MB of price data.
-What is the best way to get and then store the price data for each ticker in the universe? Are we looking at something like SQL or Microsoft access here? I dont know; I dont have enough awareness on the subject of handling lots of data like this. What are you thoughts?
I have used ToS to filter stocks based off of true/false parameters over a period of time in the past; however the capabilities of ToS are limited.
I would like a more flexible backtesting engine like code written in python or C#. Not sure if Rscript is of any use. - Maybe, there are libraries out there that I do not have awareness of that would make this all possible? If there are let me know.
I am aware that Quantopia and other web based Quant platforms are around. Are these my best bets for backtesting? Any thoughts on them?
Am I making this too complicated?
Backtesting a strategy on a single equity or several equities isnt a problem in excel, ToS, or even Tradingview. But with lots of data Im not sure what the best option is for storing that data and then using a python script or something to perform the back test.
Random Final thought:-Ultimately would like to explore some AI assistance with optimizing strategies that were created based off parameters. I know this is a thing but not sure where to learn more about this. If you do please let me know.
Thank you guys. I hope this wasn't too much. If you can share any knowledge to increase my awareness on the topic I would really appreciate it.
Twitter:#b_gumm
The amout of data is too much for EXCEL or CALC. Even if you want to screen only 500 Stocks from S&P 500, you will get 2,2 Millions of rows (approx. 220 days/year * 20 years * 500 stocks). For this amount of data, you should use a SQL Database like MySQL. It is performant enough to handle this amount of data. But you have to find a way for updating. If you get the complete time series daily and store it into your database, this process can take approx. 1 hour. You could also use delta downloads but be aware of corporate actions (e.g. splits).
I don't know Quantopia, but I know a similar backtesting service where I have created a python backtesting script last year. The outcome was quite different to what I have expected. The research result was that the backtesting service was calculating wrong results because of wrong data. So be cautious about the results.
I am looking to retrieve historical data like P/E ratio, earnings, book value etc as well as stock price. I'd like to go through a whole bunch of stocks programmatically or to possibly select historical stocks based on valuation rules.
I found a few python packages to download historical stock prices from Yahoo like yahoo-finance and also this guide to downloading historical prices with the browser. But I could not find anything to download historical valuation data.
I am aware of Survivorship Bias problem with the stocks that affects these free services but I can't afford a paid one right now.