Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I had a similar problem with one of my batch files. I think it is related to the path (I can't find any definitive proof). Most of my batch files were located in the C:\Span4 folder, but I had 2 in the sub-folder C:\Span4\SpanPosConv. The name of the Batch had a space in it and it just flashed the cmd window when I tried to run it in VBA as "C:\Span4\SpanPosConv\SpanPosConv RJO.bat". My other batch files in the C:\Span4 folder had spaces in their name and worked fine when called through VBA.
I removed the space in the name of the batch and was able to call it as "C:\Span4\SpanPosConv\SpanPosConvRJO.bat". I also tried moving the batch to the C:\Span4 folder and leaving the name with the space and that also worked calling "C:\Span4\SpanPosConv RJO.bat".
You mentioned that your batch works fine when you click on it, so it should not be an error in the batch. The name of your batch does not have a space, but it is in a sub folder. I have no idea why it would have issues with the path, but I would recommend moving the batch to the C:\Span4 folder and modify your sub:
Sub RunSPANBatchfile()
Dim RetVal
Dim batchfile as string
batchfile = "C:\Span4\SPANBatch.bat"
RetVal = Shell(batchfile, 1)
End Sub
I was able to get this to work by editing only a few lines of that text that was in the file I upload. Now I can run one sub that can call multiple batch files, wait for each to complete before running the next, and then run additional code. I can walk you through that if you are interested.
I moved the batchfile to SPAN4. And then copied and pasted your sub. I now get the error that SPANData.dll is not on my computer. I moved the SPANData.dll from the Bin folder to the SPAN4 folder and I still get the same error message.
I have used too much time on trying to get this to work. I need to move on. Your download risk files sub has been a big help thanks.
I'm sorry that it didn't help. I know the dll file needs to be in the same folder as the spanit.exe. The error makes me think that there might be something in the batch file or span script that might be throwing it off (file name or path of batch that has changed). If you decide later to give it another go, I'll be happy to try to help you troubleshoot.
It's pretty painless.
1- copy all the code from the text file uploaded and paste it above all of your other code in your module.
(all of the "Option Explicit", "Private Declare Function" and "Private Const" lines need to be on top, above all the subs ... if you have any other "Private Declare Functions" they'll have to be moved above the subs as well)
2- edit the "Sub Run_bat()" as needed. It is currently set to run 2 batch files and then call another sub "copy_data_RJO" in my spreadsheet ... just change the name/path of the batch files: "C:\Span4\SPAN Risk RJO.bat" and "C:\Span4\SPAN RiskRep RJO.bat" and insert code to call other subs as needed.
I am thinking that simply listing them into a portfolio csv file and loading them up with SpanPosConv (net position of 1 each) and calculating the perf bond req will calculate the margins for each as part of a spread within the portfolio etc - But i am hoping to get just the straight margin for each as if it were traded independently of anything else, like if it was the only position in the portfolio....
Scott, if you put the symbol in the firm name then you will get the margin for each. That is what I do. See post #14.
SPAN will group the results by firm name with the same acct ID. So everything on the spreadsheet will the same firm name and acct ID will be calculated together to give you margin for all lines of the spreadsheet with that firm name and acct ID.
If you want margin for each contract then put your symbol in the firm name and anything in acct ID.
If you want margin for a spread, Put the same firm name and acct ID for each leg. SPAN will then combine them.
Tip: The spreadsheet must be closed in order to run the SPANPosConv batch. Also blank lines in spreadsheet are ignored.
This is how it would look if you put them into the SPAN program.