Inventory Management Software

Kardex Tauro

Kardex Tauro® Inventory Software is designed to efficiently manage your warehouse or storage facility, and it is quick and easy to learn.

Kardex Tauro is free for non-commercial use.
It does not require an internet connection; it runs on Windows.

Python code: combined moving-average and headline-sentiment signal

Python code: combined moving-average and headline-sentiment signal

This program answers one narrow question: how do you decide something with the numbers in front of you instead of a hunch? It joins two simple ideas -the moving average of twenty and fifty closes, which is nothing but the average of the last few closes, and the day's headline sentiment, measured by counting the positive and negative words a headline carries- and writes one decision for every dated headline: buy, sell or wait. It is written for the small-business owner who wants to watch a rule being measured, for the accountant who distrusts figures they cannot check, and for the warehouse clerk who is already comfortable with a table of fixed columns. You will not find a magic formula in here: you will find a scale and a sheet of paper.

⬇ Download the code (ZIP)

Notice: this is educational material for practising Python and it is not a recommendation to buy or to sell. The sample prices and the headlines shipped with the program are invented, and the historical data is quoted only for practice. A past result guarantees nothing about the future: ask a licensed professional before investing.

File inside the ZIPWhat it is
senal_combinada.pyThe program, commented in English, standard library only
datos/prices.csvOne hundred and eighty sample daily closes, invented, January to June
datos/headlines.csvThirty invented headlines with their manual label
salida_ejemplo.txtThe real output you will see on screen, exactly as it looks
README.mdInstructions, the data format and the written disclaimer

What the program does

  1. It reads two sample files shipped inside the ZIP: the daily closes and the headlines. The headlines are invented and are there for practice; they are not real news.
  2. It works out the twenty-close and the fifty-close moving average for every date. Each average uses only earlier closes: it never looks ahead, because the future is not in the file.
  3. It scores the headline with its own lexicon: two short hand-written word lists, positive and negative, with no artificial intelligence involved. The upside is that you can read the lists and argue with them; the downside is that irony slips right past.
  4. It turns that score into a three-value signal: positive when the headline leans up, negative when it leans down and neutral when it sits in the middle.
  5. It writes the decision for each date: buy only when the technical signal and the sentiment are both positive, sell only when both are negative, and wait in every other case.
  6. It saves the diary to salida/diario.csv and counts the days behind each decision.
  7. It compares the final capital of the rule against buy and hold and names the winner, even when doing nothing wins.

How to run it

You need Python 3.11 or newer and nothing else: the program uses only the standard library, so there is no package to install, no account to create and no platform to connect. Unzip the file into a folder, open the terminal in that same folder and type a single line:

python senal_combinada.py

If the terminal answers that it cannot find the file, it is almost always sitting in a different folder: move with cd into the folder you unzipped and try again. The program writes nothing outside its own folder: it creates salida/ and drops both CSV files there.

The code, explained

Five pieces of the program explain almost everything else. The first is the block of constants at the top, which fixes the starting capital and the idea of comparing both strategies on the same base:

CAPITAL_INICIAL = Decimal("100.00")                # Starting capital, so both ideas are compared on the same base

Money is handled with Decimal and never with binary decimals, because in a chain of multiplications the cent-by-cent errors pile up and the comparison stops being believable. The file keeps Spanish variable names such as capital_regla and cierres on purpose, so the three language versions can be read side by side.

The second piece is the whole decision rule: six lines. The entire strategy fits there, and that is exactly the point of the exercise.

def decidir(tecnica: int, sentimiento: int) -> str:
    """Buy only when both signals are positive; sell when both are negative."""
    if tecnica == 1 and sentimiento == 1:
        return "buy"
    if tecnica == -1 and sentimiento == -1:
        return "sell"
    return "wait"

There are three possible outcomes: buy, sell and wait. Buying demands that both signals agree upwards; selling demands that both agree downwards; any disagreement ends in wait, which in the diary is by far the most frequent decision.

The third piece is the comparison. Notice that the program never looks at the next day's price:

def comparar(filas: list[dict]) -> dict:
    """Compares the capital of the rule with buy and hold, never peeking into the future."""
    capital_regla = CAPITAL_INICIAL

The rule's capital is updated one day at a time, but only while the previous position had it in the market; waiting keeps the position that was already there, it does not invent one. The benchmark is buy and hold, meaning doing nothing, which is the most uncomfortable rival there is.

The fourth piece is the verdict, written on purpose so that it names the winner. The program has no polite branch for the case where the rule loses:

        imprimir_parrafo("Verdict: on this data the combined rule LOSES against buy and hold. It is said in plain words: the technical signal and the sentiment did not manage to stay in for the rally.")

And the fifth piece is the notice, which the program prints at the start and again at the end. The disclaimer lives inside the code, it is not tucked away in an appendix:

    imprimir_parrafo("NOTICE: " + AVISO)

What you will see on screen

First the summary of decisions and the capital comparison. This is the real output with the sample data in the ZIP:

SUMMARY OF DECISIONS
  Buy      :   7  days
  Sell     :   3  days
  Wait     :  15  days
  Total    :  25  days

COMPARISON AGAINST BUY AND HOLD
  Starting capital: 100.00
  Combined rule: 113.21  (+13.21 %)
  Buy and hold: 125.45  (+25.45 %)
  Capital difference: -12.24

  Verdict: on this data the combined rule LOSES against buy and hold. It is said in plain words: the
  technical signal and the sentiment did not manage to stay in for the rally.

Then the diary by date, with the technical signal, the sentiment and the decision in the last column. Look at the first two rows and at the last one:

Date       Close                                Headline    Avg. 20    Avg. 50     Tech.   Sentim.    Decision
2026-04-06 93.24      The index rises sharply and mar...      97.00     103.45        -1        +1        wait
2026-04-09 93.71      The price falls on fear of a ra...      96.60     102.50        -1        -1        sell
2026-06-29 116.97     The company approves a solid bu...     118.11     117.75        +1        +1         buy

The result, with no make-up

Here is the part that cannot be dressed up. On this data the combined rule ends with a capital of one hundred and thirteen point two one, that is, a rise of thirteen point two one percent. Buy and hold, which is doing absolutely nothing, ends at one hundred and twenty-five point four five, that is, twenty-five point four five percent. The gap is twelve point two four and it favours buy and hold. Put plainly: the combined rule LOSES, and the program writes it in those very words.

Why does it lose? Because putting two signals together does not create a crystal ball. A moving average is an average of the past, so by definition it arrives late to a rally; the headline, for its part, hardly ever lands on the same day the price moves. By the time both signals finally agree, a good part of the move has already happened, and the rest of the time the rule sits outside the market waiting. One further warning: a single measurement proves nothing, for or against. It may be a coincidence of this data, which is exactly why the honest thing is to say so and to measure again on other prices before drawing conclusions.

The diary hands you the numbers that really count in a business: seven days said buy, three said sell and fifteen said wait. Those fifteen waiting days are the heart of the matter. Each one has a date, a close and a written reason, and anyone can open the file and argue about it with the figures in hand. The day your accountant asks why stock was bought in that particular week, the answer is not a hunch: it is a row of the diary with the technical signal and the sentiment behind it. Whether the outcome turned out well or badly is another story, and that story can only be judged with the diary open. Writing down why each decision was made is the cheapest and most underrated tool a small business has.

How to use your own prices

The ZIP ships sample data so that you need to download nothing else, but the program is built so that you can replace the datos/ folder with your own files. The format is a plain CSV, with a header row and one row per day: open it in any spreadsheet, edit it and save it as CSV again. The historical prices used in this workshop come from CoinGecko (api.coingecko.com) for bitcoin and from the SP500 series of the Federal Reserve Bank of St. Louis, at https://fred.stlouisfed.org/series/SP500; both were downloaded on 2026-09-25 and are quoted here only as practice data.

FileColumnWhat goes in it
datos/prices.csvdateThe day as year-month-day, for example 2026-01-02
datos/prices.csvcloseThat day's closing price, with a decimal point
datos/headlines.csvdateThe headline's day, in the same format
datos/headlines.csvheadlineThe full text, in quotes if it contains commas
datos/headlines.csvlabelWhat you think it says: positive, negative or neutral

Two format warnings that save you an afternoon of frustration: the column names cannot be changed, and the file must use a comma as separator, not a semicolon. If your spreadsheet saves with semicolons, the program will stop with a column error and you will know exactly where the problem is.

Common mistakes and tips

  • Renaming a CSV column. The program looks for the exact names and stops when they are missing.
  • Leaving fewer than fifty closes. Without fifty rows there is no long average and the diary comes out empty: that is not a bug.
  • Running it from another folder. If the terminal is somewhere else, the program finds the ZIP but not the data.
  • Thinking that a waiting day is a calculation error. Waiting is a decision, and in this diary it is the most common one.
  • Reading the result as a promise. The sample prices are invented and the historical ones are quoted only for practice.
  • Changing the lexicon and expecting the sentiment to improve. Add or remove words and the decisions change: that is precisely what the diary makes visible.

When this is not enough

This program is a practice notebook, not a management system. If what you need is to put your real stock in order -ins and outs, costs, quantities per warehouse and the usual reports-, Kardex Tauro is free and is built for that; here you practise how a rule is measured, you do not run the business. A script teaches you how to look at the numbers; the system keeps the day-to-day in order, and neither of them replaces the owner's judgement.

Notice: I say it again because it matters: this is educational material and not a recommendation to buy or to sell. The source of the data is cited above in this same article, the ZIP carries the disclaimer in writing and the sample prices are invented. A past result guarantees nothing about the future; ask a licensed professional before investing.

⬇ Download the code (ZIP)

Download the ZIP, swap the data folder for your own prices and see what the diary says. Even if the rule loses, you will have learned something that serves a business for life: how to measure an idea before believing it.

Share
Link copied
Microsoft Store from Microsoft StoreDownload free
Chatea por WhatsApp