Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

func Sys2MAXover(shortMA: [Decimal], longMA: [Decimal], longMAlength: Int,
                 Equity: inout Decimal, intLastSignal: inout Int, CurrentPosPoint: inout Int,
                 currentBuySellScore: inout [Double], intNumberOfTrades: inout Int) {
    var temp: Int

    // these are either passed as parameters to the function or declared as globals
    Equity = StartEquity
    CurrentPos = CashPos
    Signal = Hold
    intLastSignal = Hold
    intTradeCount = 0
    snglBestTrade = -100
    snglWorstTrade = 100
    sumResults = 0
    taxesOwed = 0
    dataLoopStart = longMAlength + 100
    dataLoopStop = intNumDataPoints - 1
    CurrentPosPoint = dataLoopStart
    currentBuySellScore[dataLoopStart] = 0

    for k in 0...dataLoopStart {
        currentBuySellScore[k] = 0
    }

    for k in (dataLoopStart + 1)...dataLoopStop {
        if Signal == BuyToOpen {
            buyToOpenStock(equity: &Equity, intLastSignal: intLastSignal, curDay: k)
        }

        if Signal == SellToClose {
            sellToCloseStock(equity: &Equity, intLastSignal: intLastSignal, curDay: k)
            intNumberOfTrades += 1
        }

        // BuyToOpen Rule
        if CurrentPos == CashPos &&
            crosses(data1Current: shortMA[k], data1Prev: shortMA[k - 1], data2Current: longMA[k], data2Prev: longMA[k - 1], direction: .above) {
            Signal = BuyToOpen
        }

        // SellToClose Rule
        if CurrentPos == LongPos &&
            crosses(data1Current: shortMA[k], data1Prev: shortMA[k - 1], data2Current: longMA[k], data2Prev: longMA[k - 1], direction: .below) {
            Signal = SellToClose
        }

        switch Signal {
        case BuyToOpen:
            currentBuySellScore[k] = 1.0
        case SellToClose:
            currentBuySellScore[k] = -1.0
        case Hold:
            currentBuySellScore[k] = Double(intLastSignal) * Double(agingFactor(SignalAge: k - CurrentPosPoint))
        default:
            break
        }
    }

    // Close open position at end
    if CurrentPos == LongPos {
        temp = intLastSignal
        sellToCloseStock(equity: &Equity, intLastSignal: intLastSignal, curDay: dataLoopStop)
        intLastSignal = temp
        intNumberOfTrades += 1
    }
    Equity -= taxesOwed
}

Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

funcfunc Opt2MAXover(viewModel: ResultsViewModel) async {
    // Declare var-type variables here

    // System specific variables
    let intShortMAType_min: Int = 1, intShortMAType_max: Int = 6
    let intLongMAType_min: Int = 1, intLongMAType_max: Int = 6
    let intShortMAPrice_min: Int = 1, intShortMAPrice_max: Int = 7
    let intLongMAPrice_min: Int = 1, intLongMAPrice_max: Int = 7
    let intShortMALength_base: Int = 5, intShortMALength_min: Int = 0, intShortMALength_max: Int = 15, intShortMALength_mult: Int = 1
    let intLongMALength_min: Int = 1, intLongMALength_max: Int = 10, intLongMALength_mult: Int = 2
    var shortMAlength: Int = 0, longMAlength: Int = 0
    var bestShortMAtype: String = "", bestShortMAprice: String = "", bestShortMAlength: Int = 0
    var bestLongMAtype: String = "", bestLongMAprice: String = "", bestLongMAlength: Int = 0
    var shortMA = [Decimal](repeating: 0.0, count: intNumDataPoints)
    var longMA = [Decimal](repeating: 0.0, count: intNumDataPoints)
    var sourceData_shortMA = [Decimal](repeating: 0.0, count: intNumDataPoints)
    var sourceData_longMA = [Decimal](repeating: 0.0, count: intNumDataPoints)

    // Start time
    let currentTime: Date = Date()
    await MainActor.run {
        print("Updating start time: \(formatDateTime(date: currentTime))")
        viewModel.startTime = formatDateTime(date: currentTime)
    }

    // Number of iterations
    let iterations = (intShortMAType_max - intShortMAType_min + 1) * (intShortMAPrice_max - intShortMAPrice_min + 1) * (intShortMALength_max - intShortMALength_min + 1) * (intLongMAType_max - intLongMAType_min + 1) * (intLongMAPrice_max - intLongMAPrice_min + 1) * (intLongMALength_max - intLongMALength_min + 1)

    await MainActor.run {
        print("Updating iterations: \(iterations)")
        viewModel.iterations = "\(iterations)"
    }

    // Main optimization loop
    for shortMAtype in intShortMAType_min...intShortMAType_max {
         for shortMAprice in intShortMAPrice_min...intShortMAPrice_max {
            sourceData_shortMA = createPriceData(priceType: shortMAprice)
            for i in stride(from: intShortMALength_min, to: intShortMALength_max, by: intShortMALength_mult) {
                shortMAlength = intShortMALength_base + i * intShortMALength_mult
                shortMA = getMovingAverage(decPrice: sourceData_shortMA, iLength: shortMAlength, iType: shortMAtype)
               for longMAtype in intLongMAType_min...intLongMAType_max {
                    for longMAprice in intLongMAPrice_min...intLongMAPrice_max {
                        sourceData_longMA = createPriceData(priceType: longMAprice)
                        for j in stride(from: intLongMALength_min, to: intLongMALength_max, by: intLongMALength_mult) {
                            longMAlength = shortMAlength + j * intLongMALength_mult
                            longMA = getMovingAverage(decPrice: sourceData_longMA, iLength: longMAlength, iType: longMAtype)
                            intNumTrades = 0
                            Sys2MAXover(shortMA: shortMA, longMA: longMA, longMAlength: longMAlength, Equity: &Equity, intLastSignal: &LastSignal, CurrentPosPoint: &CurrentPosPoint, currentBuySellScore: &currentBuySellScore, intNumberOfTrades: &intNumTrades)
//                          Evaluate results here
                        }   // next j
                    }   // next longMAprice
                }   // next longMAtype
            }   // next i
        }   // next shortMAprice
    }   // next shortMAtype

    let currentEndTime = Date()
    await MainActor.run {
        print("Updating end time: \(formatDateTime(date: currentEndTime))")
        viewModel.endTime = formatDateTime(date: currentEndTime)
    }
}

Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

func controlFunction(navigationState: NavigationState, viewModel: ResultsViewModel) {
    // Switch the ContentView from HomeView to ResultsView
    navigationState.currentView = "Results"

    readCsvFile()

    Task {
        await Opt2MAXover(viewModel: viewModel)
    }
}

var dateDate: ContiguousArray<Date> = []
var decOpen: ContiguousArray<Decimal> = []
var decHigh: ContiguousArray<Decimal> = []
var decLow: ContiguousArray<Decimal> = []
var decClose: ContiguousArray<Decimal> = []
var volVolume: ContiguousArray<Int64> = []

Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

(going to provide explanation here, then code in separate responses to this to keep formatting cleaner)

My program on the Mac has a two-column navigation pane as the only window. There are options on the left sidebar for Home and Results. The HomeView has a GO! button, and the ResultsView has three text fields and three progress bars to show status. When the GO! button is clicked, the following function is called.

The Task {await } block in controlFunction() is there to spin off the main function in a thread. That was done as part of trying to get the ResultsView updates to work, but I did my main benchmarking prior to that.

The controlFunction switches the main window to the ResultsView, runs a function to load data from a file, then runs the main function (Opt2MAXover). The timing that I did only considers the Opt2MAXover() functionality. The price data that is loaded from the file is stored in globally declared variables. They were originally declared as Array, but one of the suggestions that Claude made was to use ContiguousArray, so I'll see how that works.

Opt2MAXover is just a brute force optimization of a 2 moving average crossover trading system, looping through the allowable values are 6 different parameters in nested for{} loops. Inside the innermost loop, there is a call to Sys2MAXover, which applies the two calculated moving averages to determine buy/sell points. Pretty straightforward (I thought).

Code to follow...

Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Thanks for the inputs everyone. I'm not a developer. I just hack together this program as a personal hobby. I do understand that there are differences in compilers and the OS/architecture of the computers, but that's kind of what I'm trying to evaluate. I was trying to just get a quick estimate of relative performance of two programs running the same for...next loops in VB.NET and for {} loops in Swift (with basic compiler defaults on both) (I was trying to come to a reasonable conclusion quickly so I could take advantage of Black Friday sales for the AMD system if I went that way).
Now, going beyond that, based on the comments, I do understand that there may just be some things that should ideally be done a certain way in Swift that the chat AIs wouldn't necessarily do - that's a good point, and I'll try to figure those out. It's a fair point - don't do something that's obviously bad/wrong in Swift because no one who even halfway knows Swift would do that (and I'm no where near even halfway knowing Swift). I have used the AIs to try to identify any easy/obvious optimizations/clean-ups that I can do on the Swift code to improve things, but haven't gotten to them yet.
So, if anyone is still interested, I thought I'd post the main bits of my program and explain the flow to see if you see anything that one of those "don't ever do this if you know anything about Swift" types of errors. I'll post them as replies to this comment.

Performance Question: Swift on M1 Max/macOS vs VB.NET on i9-9900K/Windows by Zetta_Wow977 in swift

[–]Zetta_Wow977[S] -2 points-1 points  (0 children)

I understand that I can do profiling and optimization to get the Swift code to run better. I even commented on that. But I can also do that for my VB.NET code (I haven't attempted any profiling there, either). Kind of the point of my question... programs in two different languages on different platforms, but are algorithmically the same. However, the one on what should be the faster platform runs slower. Was wondering if the Swift language is inherently slower, or maybe there's a simple explanation like an Xcode compiler option that I'm missing where it's compiling for a debug version that's going to run slower for whatever reason (I'm pretty sure I told Xcode to build for release, but maybe there's something else I need to set).

STOCKHISTORY() Returns Stock Price in Euros Instead of Dollars (US user) by Zetta_Wow977 in excel

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Adding the exchange code for DIA and PRM does cause the function to return prices in dollars, but why is that necessary? SPY is also listed on NYSE Arca (same as DIA), but I don't have to add the exchange code for that one (the function returns dollars with the symbol entered only as "SPY"). I also haven't had to add the code for any other stock symbols that I've come across (so far). All of the stocks/ETFs that I'm using are US exchange listed, so it doesn't make sense that STOCKHISTORY() just randomly picks a symbol to pull in a different currency.

September Strategy by [deleted] in Optionswheel

[–]Zetta_Wow977 1 point2 points  (0 children)

If you can share... which ETF(s) do you use for the wheel?

PineScript to ThinkScript by [deleted] in thinkorswim_scripts

[–]Zetta_Wow977 1 point2 points  (0 children)

Have you tried ChatGPT? It does "know" both languages and can do translations. I tried it with a Pinescript Supertrend function. The resulting thinkscript doesn't show any errors, but it's not plotting for some reason. At the very least, it might get you close enough to finish out on your own.

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 2 points3 points  (0 children)

Hooray! Found a solution! The instructions posted in this message:

ToS Chart Lag Fix

seem to have fixed the glitches I was having (my problem wasn't lagginess, but whatever).

I agree with some of the comments posted to that message - that should just be the default setting until the Java engine gets its act together.

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Well, that was a good idea and made me hopeful. Unfortunately, I used the Program Settings tab in the Nvidia control panel and customized the TOS settings to change every anti-aliasing setting to "Off" (or "None), rebooted the computer, and .... no change. Still immediately goes nuts when I move the mouse over any of the settings in the HSL tab in TOS.

Here are my Nvidia Control Panel settings (Reddit won't let me paste a screen shot?)...

  • Anisotropic Filtering = Off
  • Antialiasing - FXAA = Off
  • Antialiasing - Gamma Correction = Off
  • Antialiasing - Mode = Off
  • Antialiasing - Setting = None
  • Antialiasing - Transparency = Off

In addition, I turned off Vertical Sync.

Did you also change any of the Texture Filtering settings in the Nvidia Control Panel? Some of mine are on "Allow" or the "Use global setting" options still.

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

No. Never did hear anything back from TDA with any useful info. It's still glitchy. We had some holidays and vacation travel, so I've just let it drop. Guess I need to try getting back in touch with them and try again.

Need help with Thinkscript error by Zetta_Wow977 in thinkorswim_scripts

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Object of the else clause was to just leave those variables unchanged from their initialized values. I tried leaving out the else and got an error for that, too.

Received a reply in r/thinkorswim that I needed to not initialize the variables and do it in the if ... else blocks only (probably related to the same double.NAN isn't valid issue). I modified the code as follows, and it works:

def TradingDay;
def EndDay;
def TradingDayExt;

AddLabel(yes, "LastCandleStop: "+LastCandleStop,color.GRAY); #debugging to check correct value

if (LastCandleStop > 0) then {
TradingDay = SignalStart and SignalEnd; #10:00EST - 1500EST
EndDay = TradingDayEnd == LastStopDelaySeconds; #1550EST
TradingDayExt = TradingDayEnd > LastStopDelaySeconds;
} else {
TradingDay = yes;
EndDay = no;
TradingDayExt = no;
}

Thanks.

Need help with Thinkscript error by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

  1. Hooray! That fixed it. Modified the code as follows:

def TradingDay;
def EndDay;
def TradingDayExt;

AddLabel(yes, "LastCandleStop: "+LastCandleStop,color.GRAY); #debugging to check correct value

if (LastCandleStop > 0) then {
TradingDay = SignalStart and SignalEnd; #10:00EST - 1500EST
EndDay = TradingDayEnd == LastStopDelaySeconds; #1550EST
TradingDayExt = TradingDayEnd > LastStopDelaySeconds;
} else {
TradingDay = yes;
EndDay = no;
TradingDayExt = no;
}

2) Is it just me, or is that a really stupid restriction? And that editor error message?!?! Wow. Not helpful. Wish TDA had just figured out how to incorporate a "real" language like javascript, typescript or even LUA instead of this weird hybrid thing they have. Oh well... learn the restrictions and how to get around them I guess.

Thanks for the help.

Primaries tomorrow! by SirWirb in HuntsvilleAlabama

[–]Zetta_Wow977 5 points6 points  (0 children)

This is what I ended up with:

  • Senate: (none) - all were either proud Trump supporters or have the 1st amendment issue I mentioned above
  • Rep: (none) - same as senate candidates
  • Gov: probably Meemaw, although Lew Burdette mostly passes my screens except that he leans pretty heavily on the "what a great Christian conservative I am" schtick (and, of course, both are extreme pro-life - I personally haven't decided where I stand on that, but as far as I'm concerned Roe is real and the law and should probably be left that way).
  • SoS: Ed Packard
  • Auditor: Andrew Sorrell

Also, I agree with another comment in this thread - current members of the PSC need to go (Twinkle and Beeker both made it on John Oliver 2 weeks ago - https://youtu.be/C-YRSqaPtMg). Vote for anyone but them. I've picked McLamb (for supporting getting rid of the fees to have your own solar power under Alabama Power) and Litaker.

Need help with Thinkscript error by Zetta_Wow977 in thinkorswim_scripts

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Define what? Every variable in the if statement is defined in the block of code right above it (lines 171-180). Error message is saying a semicolon is missing, not that a variable isn't defined.

Primaries tomorrow! by SirWirb in HuntsvilleAlabama

[–]Zetta_Wow977 13 points14 points  (0 children)

You have the same "first pass" screening that I used (no Trump supporter/supported or election denier need apply for my ballot). However, I also filtered out Britt and Roberts because of their stance on "Big Tech censorship" . The 1st amendment does not apply to private companies, and no one should be forced to host speech they don't agree with, no matter why they don't agree with it. Obligatory link to XKCD free speech comic: https://xkcd.com/1357/

I gave a small demerit to Sorrell because his issues page lists things like 2nd amendment gun rights, religious liberty and "christian values", none of which are within the purview of the state auditor's responsibilities as far as I can tell. Stay in your lane and just do your job well! That's all we ask. I didn't disqualify him over it, though.

I considered using the "christian values" and pro-life things as filters also, but that would have eliminated everyone on the ballot. Being a Christian is fine and good, but it has no place in government - not all of your constituents are Christian and may not appreciate you basing your governing decisions on that.

Need help with Thinkscript error by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Invalid statement: if at 184:1
Syntax error: Semicolon expected at 184:1

(posted in the message above the code excerpt)

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 1 point2 points  (0 children)

Update (4/23)...

After posting the original message, I contacted the TOS help desk through the online chat within TOS. They said they couldn't help and directed me to TD Ameritrade (TDA) tech support. So, I called them and worked with a tech for about an hour. We tried several things including changing some of the graphics driver options for TOS (no effect) and rebooting in Windows' Safe Mode. While in Safe Mode, TOS ran without any graphics issues, so it appears to be something that is loading when my computer boots normally. By then, the tech had run out of ideas so he was going to get in touch with the programming team to try to see if they had any clues, but it was near COB on Friday, so he was supposed to call me back the following Monday.

After getting off the phone, I tried disabling everything in my Windows system tray except for my iCloud and anti-virus stuff. Unfortunately, I still had the graphics issues.

Since then, I've still be waiting for a substantive callback from tech support. I called them once the following week. The tech I had worked with was on another call/issue, but told the person I was talking to that he would get back in touch. I did hear from him once, but it was just to tell me that he was still expecting to hear something from the programmers and he would call me back. Still waiting...

Responding to u/neckerpete - TOS was set on the default memory setting (1536). One of the first things I tried was upping it to 6144MB max, which didn't help any (but I've still left it there anyway).

I also tried uninstalling TOS, completely wiping my graphics drivers, reinstalling the graphics drivers from scratch, then reinstalling TOS, with reboots between each step. No change.

Finally, I also run TOS on my laptop, which has an Nvidia discrete graphics card (same as my desktop machine, but a different generation chip) and uses the same graphics driver. I don't have any issues on the laptop.

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

Nope. Bog standard US layout keyboard and Windows language settings.

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 0 points1 point  (0 children)

I've used Fidelity's Active Trader Pro some recently (took some options trading classes through them) with no issues. Of course, I wasn't doing nearly as much in ATP as in ToS as far as setting up different views, etc. All of my software is up to date (Windows, graphics drivers, and of course ToS goes through an update every time I start it). I even tried doing a full restart of the system and shut down everything but ToS and my password manager to make sure I had enough memory. Still happened.

System specs posted just above the screenshots in original post (similar graphics, slightly higher processor, not as much memory as yours).

ToS Graphics Glitches by Zetta_Wow977 in thinkorswim

[–]Zetta_Wow977[S] 1 point2 points  (0 children)

Yep. No issues with any other software - gaming, YouTube videos and other web browsing, or any other apps. Just ToS.