Rotate script

Posted By: kalmar

Rotate script - 12/17/23 10:09

Hi all,

There is a rotate.c script in Strategy folder. Is there any description what it could be used for? I'm reading it, but would be useful if there is more explanation.

Thx
Posted By: TipmyPip

Re: Rotate script - 12/17/23 14:53

Thank you for your interest, The rotate.C strategy is a portfolio management. The strategy functions as a mathematical model for portfolio optimization, drawing from a matrix-like dataset to align current asset holdings with predefined targets. It employs vector comparisons to calculate trade adjustments, ensuring alignment through sequential logic. Human oversight is integrated through a confirmation step before trade execution. The strategy then iteratively adjusts each asset's position, mirroring the process of solving a system of equations. Post-execution, a detailed log akin to an annotated mathematical proof records the strategy's actions, encapsulating a blend of algorithmic precision and strategic decision-making.
Posted By: kalmar

Re: Rotate script - 12/17/23 20:41

Sounds like Zorro GPT answer laugh
Posted By: TipmyPip

Re: Rotate script - 12/20/23 12:38

Well, your income sure depends on how flexible you can be, and adapt Technology.
Posted By: TipmyPip

Re: Rotate script - 12/28/23 14:47

Has anyone tried this code and found a way to improve it? Zorro S version has functions that can incorporate better remote algorithmic control

Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TO_CSVHDR "Asset,Weight%%,Margin,Lots,MarginCost"
#define TO_CSV "\n%s,%.0f,%.0f,%.0f,%.0f"

char* Filename = "Data\\MyStrategy.csv"; // rotation list
char* Fileformat = "ss,f,f,f";
char* Outfile = "Log\\Rotation.log";
char* TickerSymbol = "*";
// char* TickerSymbol = "*-STK-SMART-USD!STOOQ:*";
#define NEWWEIGHT 1 // weight percent field number
#define NEWLOTS 3   // lots field number
#define LEVERAGE 1

double AssetInt[12]; // Assuming AssetInt is an array of doubles

void folioTrade(int LS) {
    // Assuming used_assets is an array of asset names
    for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {
        asset(used_assets[i]);
        if ((OpenLots > NewLots && LS < 0) || (OpenLots < NewLots && LS > 0)) {
            enterLong(NewLots - OpenLots);
        }
    }
}

int main() {
    int i;
    int Records;
    double Invest = 0;

    LookBack = 0;
    StartDate = NOW;
    set(LOGFILE);
    SaveMode = 0;

    Filename = file_select("Data", "Rotation Lists\0*.csv\0\0");
    Records = dataParse(1, Fileformat, Filename);
    if (!Records) {
        return quit("CSV file not found");
    }

    printf("\nSubscribing %i assets..", Records);
    brokerCommand(SET_PRICETYPE, 8); // get prices fast
    char Box[50000] = "\n---------------------------------";
    int Changed = 0;

    for (i = 0; i < Records; i++) {
        printf(".");
        char* Ticker = dataStr(1, i, 0);
        assetAdd(Ticker, TickerSymbol);
        if (!asset(Ticker)) continue;
        NewLots = dataVar(1, i, NEWLOTS);
        OpenLots = brokerCommand(GET_POSITION, Ticker);
        double Margin = NewLots * priceC(0) / LEVERAGE;
        Invest += Margin;

        if (OpenLots != NewLots) {
            Changed = 1;
            strcat(Box, strf("\n%s \t%d -> %d@%s ($%.2f)",
                Asset, OpenLots, NewLots, sftoa(priceC(0), 2), Margin));
        } else if (OpenLots) {
            strcat(Box, strf("\n%s \t%d@%s ($%.2f)",
                Asset, OpenLots, sftoa(priceC(0), 2), Margin));
        }
    }

    strcat(Box, "\n---------------------------------");
    strcat(Box, strf("\nTotal margin $%s at %s",
        sftoa(Invest, 4), strdate(YMDHMS, NOW)));

    if (!Changed) {
        printf("\nPortfolio unchanged");
    } else {
        strcat(Box, "\nModify Portfolio?");
        if (msg(Box)) {
            strcat(Box, " Y");
            setf(TradeMode, TR_GTC);
            folioTrade(-1); // Short
            folioTrade(1);  // Long
            file_append(Outfile, Box, 0);
            exec("Editor", Outfile, 0);
        } else {
            printf("\nNo positions entered");
        }
    }

    return 0;
}
Posted By: AndrewAMD

Re: Rotate script - 12/28/23 14:58

Code
for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {
This GPT-generated code clearly does not know how the Zorro macros work. It seems to think the macro is a struct.

You should discipline your GPT.
Posted By: TipmyPip

Re: Rotate script - 12/29/23 18:19

Thank you for your suggestion Andrew, we always want to improve on our knowledge, and abilities to cooperate.

The code is meant for users to explore, learn, and try out new ideas... If I will share code without errors, no one will learn anything new, and just forget about it in 4 hours. (In addition, when you are inspired by different ideas, you improve your level and go beyond your limits, because loops aren't structures, rather than building blocks that require you to dig deeper, and find ideas you have not thought about.)

It would be even more informative for you to work with it together and improve your own ideas... We are all here to learn together.

In addition, users will enjoy your input even more, when you too share some code and explain yourself, we are all here to enjoy your contribution, please...

And remember you are always blessed, with happiness and money as well as new ideas.
Posted By: TipmyPip

Re: Rotate script - 12/30/23 16:48

Dear Andrew, I believe that you are a very clever person and a great programmer...

Would you kindly please share with us your understanding, and knowledge of what is the reason you think the following statement has anything to do with struct and why are you referring to macros?

Code
for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {


We truly want to learn from you... Thank you.
© 2024 lite-C Forums