I was trying to implement the Optopsy code for backtesting option strategies.
I get as far as pip install optopsy on the instructions and then I'm not sure how to implement the next line:
python strategies/sample_strategy.py
Also, which folder do you save the data file in?
For this line
data = op.get(FILE, SPX_FILE_STRUCT, prompt=False)
do you put the actual file name and location?
Website link to the code is below:
https://pypi.org/project/optopsy/
Thank you, RK
I had the same trouble from the posted example in the early days of Optopsy development. The snippet was incomplete. The author Michael Chu has since improved and published his source code.
Try this module and corresponding data from:
https://github.com/michaelchu/optopsy.
It is the same data file that you have. "./data/Sample_SPX_20151001_to_20151030.csv"
and the code you started with is now complete, working great and found here
https://github.com/michaelchu/optopsy/blob/master/samples/spx_singles_example.py
This Optopsy is a phenomenal library. The Optopsy v 2.0 is now the current.
Other Python backtesting libraries bt., backtrader, pyalgotrade, quantopian, zipline and pysystemtrade account for underlying backtesting and frustratingly suffer from insufficient testing available for options.
Feel free to reach out if you have a question I am actively using Optopsy works great with v3.7 and the output is straight to the point displaying your results in a pleasant formant.
Yes to your question with line
data = op.get(FILE, SPX_FILE_STRUCT, prompt=False)
You do need your current directory. I think you want something like this:
def filepath():
curr_file = os.path.abspath(os.path.dirname(__file__))
return os.path.join("./your_directory/sample_spx_strategy.py" , "SPX_20151001_to_20151030.csv")
I find I need to change all backslashes to forward slashes when you copy paste your full path.
-Cloihdna
Related
I'm currently looking to make an updater program for my plugins for guildwars 2, but I got a little issue for the last download. The name of the file to download isn't consistent from version to version as you can see there. Asking the creator to update it so it is consistent is already something that has been done some month ago, but as the updates are fairly rare and nothing has been done.
Would there be a way to get either all the release files, or to downlaod the using filter so it doesn't get the other ones?
For now i've been using the following code to download the other plugins and write them to the corresponding file, but this method doesn't work at all with that specific one because the name of this release changes.
(using python 3.9.6)
import requests
test = requests.get('https://github.com/knoxfighter/arcdps-killproof.me-plugin/releases/latest/download/d3d9_arcdps_killproof_me.dll', allow_redirects=True)
print("code :" + str(test.status_code))
open('d3d9_arcdps_killproof_me.dll', 'wb').write(test.content)
Any ideas on how I could work arround this and still download this last plugin?
If you're looking for an example of how to call git pull from within python, this seems to be a good solution:
The code is using this library:
https://github.com/gitpython-developers/GitPython
import git
g = git.cmd.Git(git_dir)
g.pull()
I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py
First of all, please excuse me if I'm using some of the terminology incorrectly (accountant by trade ...)
I'm writing a piece of code that I was planning to pack as .exe product.
I've already included number of standard libraries (xlrd, csv, math, operator, os, shutil, time, datetime, and xlwings). Unfortunately, when I've added 'dataextract' library my program stopped working.
dataextract is an API written specifically for software called Tableau (one of the leading BI solutions on the market). Also Tableau website says it does not provide any maintenance support for it at the moment.
I've tested it on very basic setup:
from xlwings import Workbook, Sheet, Range
Workbook.set_mock_caller(r'X:\JAC Reporting\Tables\Pawel\Development\_DevXL\Test1.xlsx')
f = Workbook.caller()
s = raw_input('Type in anything: ')
Range(1, (2, 1)).value = s
This works perfectly fine. After adding:
import dataextract as tde
The Console (black box) will only flash on the screen and nothing happens.
Questions:
Does library (in this case 'dataextract') has to meet certain criteria to be compatible with py2exe?
As Tableau does not maintain the original code, does it mean I won't be able to pack it into .exe using py2exe?
Finally: I'm using 'dataextract' for almost 2 years now and as long as you will run the program through .py file it works like a charm :) I just decided to take it one step further.
Any comments/input would be greatly appreciated.
EDIT:
Not sure does it help or not, but when I tried to run the same script using cx_Freeze compiler got below error:
First of all massive thanks to #Andris as he pointed me at the correct direction.
It turned out dataextrac library dlls are not automatically copied while compiler is running. Therefore you need to copy them from 'site-package/dataextrac/bin' into 'dist' folder.
Also from 12 dlls you only need 9 of them (I tried running exe file for each of them). One you don't need are: icin44.dll, msvcp100.dll and msvcr100.dll.
To be on the safe side I will be coping them anyway though.
Hope this post will be any help to otheres :)
I am using Xyce which is a circuit simulator. I am using it to export a .CSV file and a .prn file. I found Xycegnuplot.py "https://github.com/OpenXyce/Xyce/blob/master/utils/gnuplotXyce.py". I am trying to use it to plot my output variables from Xyce, howver, every time I run gnuplotXyce.py as mentioned by its author I get an error " Import Error" at the "from finblock import findblock" line and I don't know what is that error.
Please help.
Thanks
If you are going to use Xyce, you should probably get the official version from Sandia National Laboratories instead of from the OpenXyce site on github. This version was forked by an anonymous github user, and has not been updated since last fall. Since that update, Sandia released Xyce 6.2 and the OpenXyce creator did not import the new release.
You should also probably join the xyce-users group on googlegroups, where the Xyce developers monitor all questions and try to answer them promptly. It is only by happenstance that I found your question here on stackoverflow.
The "gnuplotXyce.py" script is not really maintained, and might not have been kept working with all the changes that have been made to Xyce since its release. That said, the python script depends on a number of python modules including gnuplot-py which should be available from http://gnuplot-py.sourceforge.net. The "findblock.py" module that you say cannot be found is also present in the "utils" directory of the Xyce source code, alongside gnuplotXyce.py. If you have the whole utils directory downloaded, this error should go away.
I just tried gnuplotXyce.py on a simple netlist with csv output and it didn't work, so my assumption is that the script was not maintained and will need to be fixed.
The script does sort of work if you use the native Xyce standard (.prn) format (i.e. don't specify "format=csv" on your .print line). Unfortunately, it does not leave the window open after it finishes plotting, so it is rather useless. If you use the "--ps" option, though, a correct postscript file will be created that can be viewed in any postscript viewer, or printed on a postscript printer (or through a properly set-up Linux CUPS printer that understands postscript).
The CSV format in Xyce was primarily created in order to allow import into spreadsheets such as Excel or OpenOffice-scalc, which programs have their own plotting utilities.
The ".prn" standard format works well in gnuplot. There is an example of how to use gnuplot to do this display in the document "Using Open Source Schematic Capture Tools With Xyce" on the Sandia Labs Xyce web site (in the documentation and tutorials section).
The official Xyce web site is http://xyce.sandia.gov/
I'm looking for a good python module to generate pdf417 barcodes. Has anyone used one they liked?
Ideally I would like one with as few dependencies as possible, and one that runs on both linux and MacOSX.
We recently had to approach this problem as well, and being a Python shop we wanted a Python solution. It become clear the elaphe is the project that had the potential to actually accomplish pdf 417 barcode.
However what we found was it errors by todays standards, and so we entered the hunt to fix the library. Turns out elaphe must generate an outdated form of *.eps post script that can't be interpreted by ghost script and this is where the bar code generation fails.
Well fortunately elphae uses a common library behind the scenes called Barcode Writer in Pure PostScript # http://bwipp.terryburton.co.uk
This common backend library which has many projects in multi-languages using it to generate projects. The fix specifically for us was to fork elaphe, and correct it's *.eps file generation.
To determine what is broken in the *.eps, look at this other site that is made using postscriptbarcode, and it let's you generate the pdf417 barcode online (as well as other formats): http://www.terryburton.co.uk/barcodewriter/generator/
Once you generate a pdf417 barcode it gives you the option to download the .png, .jpg, and YES the .eps file!
Using this .eps file you can pipe it to ghost script and tweak the parameterization to get the exact pdf417 barcode you are looking for. Then take this result and integrate it into the elaphe library and actually get a pull request on that thing ....
Seems to be a bit of work, but nothing that can't be knocked out in an afternoon. It is ideal to get the elaphe library back in shape to generate these without making this enhancement.
Please note that the performance of this approach for us is a few seconds to generate this barcode due to the fact it creates the 2000 line eps file and pipes it to ghost script which generates another image file that we send back as the final barcode result. This is not as performance as code128 with reportlab.
Perhaps room for optimizations: Is pillow faster than PIL in anyway? Do we need all the parts of the eps file to generate the barcode of type pdf417? Other ways to optimize?
Anyway, great question Ken and I hope you find this to be a great answer.
I guess the issue in elaphe reported by Matteius in 2013 has been fixed, since the issues and commit logs show updates on the pdf417 topic since then.
Anyway, there are now a few other options (got the list with either pip search elaphe or pip search pdf417) :
elaphe ;
elaphe3 (fork of elaphe tested against python3) ;
candybar (no documentation ? also a webservice) ;
pdf417gen ;
treepoem (about the name : barcode -> bark ode -> tree poem =D ) — edit : didn't dig the issue, but as of today generation of PDF417 seems broken.
All but pdf417gen support several types of barcodes.
Note that the documentation of bwipp (on which are based elaphe and treepoem) only mentions 5 levels of error correction (1 to 5), while pdf417gen claims to support 9 security levels (0 to 8).
Reportlab does have an extension called rlbarcode, but this one does not include support for pdf417 codes. I do not know of any other extension for reportlab including support for pdf417 bar codes.
Anyway, if you are interested in generation of pdf417 codes from python, you may be interested in this project: elaphe.
I have still not tested it (in fact, I need to generate pdf417 from python, and I found this thread as well as the elaphe project page) I am going to download the elaphe tools in order to test it right now.